<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../vue.js'></script>
</head>

<body>
    <!-- 组件的模板 -->
    <div id='app'>
        <button @click="count++">点击更新{{count}}</button>
    </div>
</body>
<script>
    // 组件
    const app = {
        data() {
            return {
                count: 100
            }
        },
        methods: {},
        beforeCreate() {
            console.log('组件创建之前');
        },
        created() {
            // 以前该方法用的多，老程序员会在这里发送数据请求
            console.log('组件创建完成');
        },
        beforeMount() {
            console.log('组件挂载之前');
        },
        mounted() {
            // 现在，我们以后都在这里发送数据请求
            console.log('组件挂载完成');
        },
        beforeUpdate() {
            console.log('组件更新之前');
        },
        updated() {
            console.log('组件更新完成');
        },
        beforeUnmount() {
            console.log('组件卸载之前');
        },
        unmounted() {
            console.log('组件卸载完成');
        },
    }

    const myapp = Vue.createApp(app)
    myapp.mount('#app')

    setTimeout(() => {
        // 卸载组件
        myapp.unmount('#app')
    }, 5000);
</script>

</html>